package u.can.i.up.gearmanimpl.common;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;

import org.apache.commons.codec.digest.DigestUtils;

public class Utils {
	public static String md5(byte[] content) {
		return DigestUtils.md5Hex(content);
	}
	
	/**
	 * 读文件内容到String
	 * 
	 * @param filePath
	 * @return
	 */
	public static String readFileToString(String filePath) {
		if (filePath.isEmpty() || filePath == null)
			return null;

		String fileContent;
		BufferedInputStream bis = null;
		try {
			File file = new File(filePath);
			Long length = file.length();
			bis = new BufferedInputStream(new FileInputStream(file));
			byte[] content = new byte[length.intValue()];
			bis.read(content);
			fileContent = new String(content);
			System.out.println(DigestUtils.md5Hex(content));
		    fileContent =(DigestUtils.md5Hex(content));
			bis.close();
		} catch (Exception e) {
		
			//System.out.println("Read file [" + filePath + "] error. " + e.getMessage());
			
			return null;
		}
		return fileContent;
	}
}
